package com.nut.spp.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateUtil {

    public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";

    public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(YYYYMMDDHHMMSS);

    public static final DateTimeFormatter DAY = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public static final DateTimeFormatter YYYYMMDD = DateTimeFormatter.ofPattern("yyyyMMdd");
    public static final DateTimeFormatter YYYYMMDD_HHmmss = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static final DateTimeFormatter YYYYMM = DateTimeFormatter.ofPattern("yyyyMM");

    public static final DateTimeFormatter yyMMdd = DateTimeFormatter.ofPattern("yyMMdd");

    public static final String MIN = " 00:00:00";
    public static final String MAX = " 23:59:59";

    public static final LocalDateTime toDateTime(String time) {
        return LocalDateTime.parse(time, YYYYMMDD_HHmmss);
    }

    public static final String toStringDay(Integer val) {

        String str = val.toString();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 8; i++) {
            if (i == 4 || i == 6) {
                sb.append("-");
            }
            sb.append(str.charAt(i));
        }

        return sb.toString();
    }


    public static final String getNowDateTime() {
        //线程安全
        return YYYYMMDD_HHmmss.format(LocalDateTime.now());
    }

    public static final String getDateTimeStr(LocalDateTime date) {
        //线程安全
        return YYYYMMDD_HHmmss.format(date);
    }

    public static final String getNowDate() {
        //线程安全
        return YYYYMMDD.format(LocalDateTime.now());
    }

    public static final String getYearPlus(int years) {
        //线程安全
        return DAY.format(LocalDateTime.now().plusYears(years)) + MAX;
    }

    public static final String getNowMonth() {
        //线程安全
        return YYYYMM.format(LocalDateTime.now());
    }

    public static final String getYYMMdd(int days) {
        //线程安全
        return yyMMdd.format(LocalDateTime.now().plusDays(days));
    }


    public static void main(String[] args) {

        System.out.println(getYearPlus(1));

    }


}
